/*
APPENDIX TABLE 1
Robustness of Association Between Firm-Level Exposure to PSL Mandates and Workers' Reports of Access to PSL in Non-PSL Mandate Places —Excluding 2020/2021 & ACS Weighting
*/

cd "$exhibits_path"

use "$data_path/main_analysis_file.dta", clear

* define controls
	global demog i.gender i.race2_harm c.age_text_clean i.kids i.eslhome i.enrolled i.cohabstatus
	global work i.manager i.longwork_yrs i.union c.hourwage_clean c.usualhours_clean 
	global statechars c.unionmem_pc c.unemp_rate  c.minwage_state  	c.race_black c.race_amind c.race_asian c.race_pacisl c.race_other c.race_multi c.hispan c.age_u5 c.age_5to9 c.age_10to14 c.age_75to84 c.age_85plus c.female_pc c.educ_pc_hsgrad c.educ_pc_somecoll c.educ_pc_assoc c.educ_pc_bach c.educ_pc_grad
	global empchars i.shift_ind c.total_emps c.total_ests

	
* defining appendmodels program for table formatting
capture program drop appendmodels
program appendmodels, eclass
// using first equation of model
       syntax namelist
       tempname b V tmp
       foreach name of local namelist {
           qui est restore `name'
           mat `tmp' = e(b)
           local eq1: coleq `tmp'
           gettoken eq1 : eq1
           mat `tmp' = `tmp'[1,"`eq1':"]
          local cons = colnumb(`tmp',"_cons")
          if `cons'<. & `cons'>1 {
              mat `tmp' = `tmp'[1,1..`cons'-1]
          }
          mat `b' = nullmat(`b') , `tmp'
          mat `tmp' = e(V)
          mat `tmp' = `tmp'["`eq1':","`eq1':"]
          if `cons'<. & `cons'>1 {
              mat `tmp' = `tmp'[1..`cons'-1,1..`cons'-1]
          }
          capt confirm matrix `V'
          if _rc {
              mat `V' = `tmp'
          }
          else {
              mat `V' = ///
             ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ ///
             ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' )
         }
     }
     local names: colfullnames `b'
     mat coln `V' = `names'
     mat rown `V' = `names'
     eret post `b' `V'
     eret local cmd "whatever"
end

	
**main results
eststo main_emps: mi est, post: reg benefits_paidsick c.pct_emps_psl_place $demog  $work $statechars $empchars  i.statelist i.year##i.month if  psl_law_places_hybd == 0, vce(cluster statelist)
	local n_main = e(N)
eststo main_ests: mi est, post: reg benefits_paidsick c.pct_ests_psl_place $demog  $work $statechars $empchars  i.statelist i.year##i.month if  psl_law_places_hybd == 0, vce(cluster statelist)
	
	
**robustness check 1: exluding 2020/2021 observations
preserve

	drop if inlist(year, 2020,2021)
		eststo exc_year_emps: mi est, post: reg benefits_paidsick c.pct_emps_psl_place $demog  $work $statechars $empchars  i.statelist i.year##i.month if  psl_law_places_hybd == 0, vce(cluster statelist)
			local n_exc_year = e(N)
		eststo exc_year_ests: mi est, post: reg benefits_paidsick c.pct_ests_psl_place $demog  $work $statechars $empchars  i.statelist i.year##i.month if  psl_law_places_hybd == 0, vce(cluster statelist)
		
restore
	

**robustness check 2: weighting
eststo weight_emps: mi est, post: reg benefits_paidsick c.pct_emps_psl_place $demog $work $statechars $empchars i.statelist i.year##i.month if psl_law_places_hybd == 0 [aw=acs_wt1], vce(cluster statelist)
	local n_weight = e(N)
eststo weight_ests: mi est, post: reg benefits_paidsick c.pct_ests_psl_place $demog $work $statechars $empchars i.statelist i.year##i.month if psl_law_places_hybd == 0 [aw=acs_wt1], vce(cluster statelist)	
	
eststo main: appendmodels main_emps main_ests
	estadd local samplesize "`n_main'": main
eststo exc_year: appendmodels exc_year_emps exc_year_ests
	estadd local samplesize "`n_exc_year'": exc_year
eststo weight: appendmodels weight_emps weight_ests
	estadd local samplesize "`n_weight'": weight
	
estadd local demog "\checkmark": main exc_year weight
estadd local work "\checkmark": main exc_year weight
estadd local firm "\checkmark": main exc_year weight
estadd local state_cont "\checkmark": main exc_year weight
estadd local state_fe "\checkmark": main exc_year weight
estadd local year_fe "\checkmark": main exc_year weight
	
estadd local exclude "\checkmark": exc_year
estadd local weighting "\checkmark": weight

esttab main exc_year weight using "$exhibits_path/Appendix Table 1.tex", ///
	keep(*psl*) mtitles("M1" "M2" "M3") mgroups("PSL Access in Non-Mandate Places", pattern(1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
	varlabel(pct_emps_psl_place "\hspace{0.5cm} Percent of Workers" pct_ests_psl_place "\hspace{0.5cm} Percent of Establishments") ///
	refcat(pct_emps_psl_place "\textit{Share in a PSL Covered State or County}", nolabel) ///
	scalars("demog \\ Demographic Controls" "work Work Controls" "firm Firm Controls" "state_cont State Controls" "state_fe State FE" "year_fe Year, Month, Year $\times$ Month FE" "exclude \\ \textbf{Excluding 2020/2021}" "weighting \textbf{ACS Weighting}" "samplesize \\ \textit{N}") ///
	noomitted noconstant nonumbers nonote noobs not nodepvars eqlabels(none) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(%9.3f) ///
		replace
